#include "myScreen.h"

MyScreen::MyScreen()
{
}

MyScreen::~MyScreen()
{
}

void MyScreen::Render()
{
	this->pEngine->GetGraphics()->DrawCamera(this->pMyCamera);

	this->pEngine->GetGraphics()->EnableDepthTesting();

	this->pEngine->GetGraphics()->DrawEntity(this->pMyEntity);

	this->pEngine->GetGraphics()->DisableDepthTesting();

	this->pEngine->GetGraphics()->Setup2DProjection();
}

void MyScreen::Update(float fDelta)
{
	this->pMyEntity->Turn(60.0f * fDelta, 60.0f * fDelta, 0);
}

void MyScreen::Load()
{
	this->pMyCamera = new Camera(0, 0, this->ScreenWidth(), this->ScreenHeight());
	this->pMyCamera->SetPerspectiveProjection(60.0f, 1.33f, 0.1f, 300.0f);
	this->pMyCamera->SetBackgroundColor(Color(255, 189, 38));
	this->pMyCamera->Move(0, 0, 5);

	this->pMyEntity = new StaticEntity();
	this->pMyEntity->AddModel(Model::CreateCube(1, 1, 1));

	Mesh *pMesh = this->pMyEntity->GetModel(0)->GetMesh();
	
	// Top
	pMesh->GetVertex(0)->color = Color(255, 0, 0); pMesh->GetVertex(1)->color = Color(255, 0, 0);
	pMesh->GetVertex(2)->color = Color(255, 0, 0); pMesh->GetVertex(3)->color = Color(255, 0, 0);

	// Bottom
	pMesh->GetVertex(4)->color = Color(255, 255, 0); pMesh->GetVertex(5)->color = Color(255, 255, 0);
	pMesh->GetVertex(6)->color = Color(255, 255, 0); pMesh->GetVertex(7)->color = Color(255, 255, 0);

	// Back
	pMesh->GetVertex(8)->color = Color(0, 255, 0); pMesh->GetVertex(9)->color = Color(0, 255, 0);
	pMesh->GetVertex(10)->color = Color(0, 255, 0); pMesh->GetVertex(11)->color = Color(0, 255, 0);

	// Front
	pMesh->GetVertex(12)->color = Color(0, 255, 255); pMesh->GetVertex(13)->color = Color(0, 255, 255);
	pMesh->GetVertex(14)->color = Color(0, 255, 255); pMesh->GetVertex(15)->color = Color(0, 255, 255);

	// Left
	pMesh->GetVertex(16)->color = Color(0, 0, 255); pMesh->GetVertex(17)->color = Color(0, 0, 255);
	pMesh->GetVertex(18)->color = Color(0, 0, 255); pMesh->GetVertex(19)->color = Color(0, 0, 255);

	// Right
	pMesh->GetVertex(20)->color = Color(255, 0, 255); pMesh->GetVertex(21)->color = Color(255, 0, 255);
	pMesh->GetVertex(22)->color = Color(255, 0, 255); pMesh->GetVertex(23)->color = Color(255, 0, 255);

	pMesh->BuildMesh();
}

void MyScreen::Unload()
{
	this->pMyEntity->Destroy();

	delete this->pMyCamera;
	delete this->pMyEntity;
}